<template>
  <div :style="{height:nowheight , width:nowwidth}">
    <Echart
      v-if="chartstau"
      :options="options"
    />
  </div>
</template>

<script>
import Echart from "../../baseMain/index.vue";
export default {
  components: {
    Echart
  },
  props: {
    nowwidth: {
      type: String,
      default: () => "600px"
    },
    nowheight: {
      type: String,
      default: () => "300px"
    },
    cdata: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      chartstau: true,
      options: {}
    };
  },
  watch: {
    cdata: {
      handler(newData) {
        this.options = {
          //   title: {
          //     text: newData.title,
          //     textStyle: {
          //         color:'#fff',
          //         fontSize:'12',
          //     },
          //     left: 'center'
          //   },
          color: [
            "#8378ea",
            "#37a2da",
            "#9fe6b8",
            "#ffdb5c",
            "#ff9f7f",
            "#32c5e9",
            "#fb7293",
            "#e7bcf3"
          ],
          tooltip: {
            trigger: "axis"
          },
          toolbox: {
            show: true
          },
          grid: {
            left: "0",
            right: "20",
            bottom: 0,
            top: "10",
            containLabel: true
          },
          xAxis: {
            type: "category",
            // boundaryGap: false,
            boundaryGap: true,
            data: newData.xAxisdata,
            axisLabel: {
              interval: "auto",
              margin: 5,
              fontSize: 12
            }
          },
          yAxis: {
            type: "value",
            axisLabel: {
              fontSize: 10
            },
            min: 0,
            interval: newData.yAxis
          },
          calculable: true,
          legend: {
            show: false,
            orient: "horizontal",
            icon: "circle",
            bottom: 0,
            x: "center",
            data: newData.xData,
            axisLabel: {
              color: "#fff"
            }
            // textStyle: {
            //   color: "#fff"
            // }
          },
          series: newData.seriesData
        };
      },
      immediate: true,
      deep: true
    },
    // 应为最内层的高度固定为百分之百，所以写这里
    nowheight: {
      handler(e) {
        this.nowheights = e
        this.resetsty()
      },
      deep: true
    },
    nowwidth: {
      handler(e) {
        this.nowwidth = e
        this.resetsty()
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    // 重置样式
    resetsty() {
      // alert("jkjk")
      this.chartstau = false
      this.$nextTick(
        () => {
          this.chartstau = true
        }
      )
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
